package com.yohann.designPattern.iterator.iterator;

import com.yohann.designPattern.iterator.department.Department;

import java.util.Iterator;

/**
 * <p>
 * 计算机学院迭代器
 * </p>
 *
 * @author Yohann
 * @since 2021/2/12 15:55
 */
public class ComputerCollegeIterator implements Iterator {
    private Department[] departments;
    private int position = 0;

    public ComputerCollegeIterator(Department[] departments) {
        this.departments = departments;
    }

    @Override
    public boolean hasNext() {
        return position < departments.length && departments[position] != null;
    }

    @Override
    public Object next() {
        Department department = departments[position];
        position += 1;

        return department;
    }
}